package com.dldata.devtools30.repository.devtexcel;


import com.dldata.devtools30.entity.DevtExcelFieldEntity;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**

 */
@Repository
public interface DevtExcelFieldDao extends com.dldata.devtools30.repository.BaseRepository<DevtExcelFieldEntity,String>, JpaSpecificationExecutor<DevtExcelFieldEntity> {
        
        @Query("select t from DevtExcelFieldEntity t order by t.xh")
        public List<DevtExcelFieldEntity> getAllFormType();
        

        
        

        
        @Query("select t from DevtExcelFieldEntity t where t.id = ?1 order by t.xh")
        public DevtExcelFieldEntity getById(String id);

        @Query("select t from DevtExcelFieldEntity t where t.name = ?1 and t.excelId=?2    order by t.xh")
        public DevtExcelFieldEntity getDistinctName(String name,  String excelId);

        @Query("select t from DevtExcelFieldEntity t where t.fieldId = ?1 and t.excelId=?2    order by t.xh")
        public DevtExcelFieldEntity getDistinctField(String fieldId,  String excelId);

        @Query("select f.id as id,f.xh as xh,f.name as name,field.fieldName as fieldName, field.fieldCode as fieldCode,field.id as fieldId    from DevtExcelFieldEntity f  inner join DevtExcelEntity z on z.id=f.excelId and f.excelId = ?1 inner join  DevtModelMetadataFieldEntity field on field.formId= z.tableId and field.id=f.fieldId and field.fieldCode <> 'ID' and field.fieldCode <> 'datatime' and field.fieldCode <> 'id' order by f.xh ")
        public List<Map> getByExcelId(String excelId);

        @Query("select f from DevtExcelFieldEntity f where f.xh = ?1 order by f.xh ")
        public List<DevtExcelFieldEntity> findByXh(Integer xh);

        @Query("select f from DevtExcelFieldEntity f where f.excelId = ?1 order by f.xh ")
        public List<DevtExcelFieldEntity> findByExcelXh(String  excelId);
}
